//
//  YunFoodResultVC.swift
//  YunChenCalculator
//
//  Created by Li Dong on 2023/10/17.
//

import UIKit
import SnapKit

class YunFoodResultVC: YunBaseVC {
    
    var model = YunFoodModel()
    lazy var contentView = UIImageView(image: UIImage(named: "img_food_result"))
    lazy var foodLabel = UILabel()
    
    init(model: YunFoodModel = YunFoodModel()) {
        super.init(nibName: nil, bundle: nil)
        self.model = model
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

        title = "查询结果"
        view.backgroundColor = .init(hex: 0xE0FFD1)
        configUI()
    }
    
    private func configUI() {
        contentView.contentMode = .scaleToFill
        view.addSubview(contentView)
        contentView.snp.makeConstraints { make in
            make.left.equalTo(25)
            make.right.equalTo(-25)
            make.top.equalTo(40)
        }
        
        foodLabel.textColor = .init(hex: 0x333333)
        foodLabel.font = UIFont.Medium(ofSize: 14)
        foodLabel.numberOfLines = 0
        contentView.addSubview(foodLabel)
        foodLabel.snp.makeConstraints { make in
            make.left.equalTo(22)
            make.top.equalTo(40)
            make.right.equalTo(-22)
            make.bottom.equalTo(-40)
        }
        
        let foodResult = "食品名称：\(model.name)\n" +
        "热量(大卡)：\(model.rl)\n" +
        "钙(毫克)：\(model.gai)\n" +
        "蛋白质：\(model.dbz)\n" +
        "脂肪：\(model.zf)\n" +
        "碳水化合物：\(model.shhf)\n" +
        "维生素C：\(model.wsfc)\n" +
        "膳食纤维：\(model.ssxw)\n" +
        "维生素E：\(model.wsse)\n" +
        "维生素A：\(model.wssa)\n" +
        "胆固醇：\(model.dgc)\n" +
        "食品种类：\(model.type)\n"
        let attri = NSMutableAttributedString(string: foodResult)
        let p = NSMutableParagraphStyle()
        p.lineSpacing = 10
        attri.addAttribute(.paragraphStyle, value: p, range: NSRange(location: 0, length: attri.length))
        foodLabel.attributedText = attri
    }
    


}
